package com.xbongbong.paas.enums.bi;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 数据集配置，更新频率枚举
 * @author zcp
 */
@Getter
public enum ConfigExecuteRateEnum {
    /**
     * 每天
     */
    DAY(1, "enum.configExecuteRate.name.day"),
    /**
     * 每周
     */
    WEEK(2, "enum.configExecuteRate.name.week"),
    /**
     * 每月
     */
    MONTH(3, "enum.configExecuteRate.name.month"),
    ;
    private Integer code;
    private String name;

    ConfigExecuteRateEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据code获取枚举
     * @param code
     * @return
     */
    public static ConfigExecuteRateEnum getByCode(int code){
        return Arrays.stream(values()).filter(cache -> Objects.equals(cache.getCode(), code)).findAny().orElse(null);
    }
    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
